#include "VertexBuffer.h"

#include <glad/glad.h>

VertexBuffer::VertexBuffer(const void *data, int size) : m_bufferSize(size)
{
    // 生成缓冲区对象名称
    glGenBuffers(1, &m_rendererId);
    // 绑定一个已命名的缓冲区对象
    glBindBuffer(GL_ARRAY_BUFFER, m_rendererId);
    // 创建并初始化缓冲区对象的数据存储
    glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
}

VertexBuffer::~VertexBuffer()
{
    glDeleteBuffers(1, &m_rendererId);
}

void VertexBuffer::bind() const
{
    glBindBuffer(GL_ARRAY_BUFFER, m_rendererId);
}

void VertexBuffer::unbind() const
{
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

int const &VertexBuffer::getSize() const
{
    return m_bufferSize;
}
